#!/opt/homebrew/bin/python3.13

# 异常处理

try:
    print("try")
    3/0
except(ValueError, IndexError) as err:
    print("except1")
    print(err)
except(ZeroDivisionError) as err:
    print("except2")
    print(err)
except(Exception) as err:
    print("except3")
    print(err)
finally:
    print("finally")


class MyError(Exception):
    def __init__(self, value): # 自定义异常类型的初始化
        self.value = value
    def __str__(self): # 自定义异常类型的string表达形式
        return ("{} is invalid input".format(repr(self.value)))

try:
    raise MyError(123)
except MyError as err:
    print("MyError")
    print(err)


